<#assign ctx=springMacroRequestContext.contextPath />
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">
    <title>后台管理平台</title>
    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html"/>
    <![endif]-->
    <link href="${ctx}/static/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="${ctx}/static/font-awesome/css/font-awesome.min.css" rel="stylesheet"/>
    <link href="${ctx}/css/style.css" rel="stylesheet"/>

</head>
<body class="fixed-sidebar full-height-layout gray-bg" style="overflow: hidden">
<div id="wrapper">
    <!--左侧导航开始-->
    <nav class="navbar-default navbar-static-side" role="navigation">
        <div class="nav-close">
            <i class="fa fa-times-circle"></i>
        </div>
        <div class="sidebar-collapse" style="background-color: #222d32;color:#FFFFFF">
            <ul class="nav" id="side-menu">
                <li class="nav-header" style="background-color: #367fa9;">
                    <div style="text-align: center;line-height: 50px;font-size: 20px;font-weight: bold;">
                        <img alt="image" style="height: 30px;" src="${ctx}/img/logo.png"/>
                    </div>
                </li>
                <li class="active">
                    <a href="#"> <i class="fa fa-home"></i> <span class="nav-label">主页</span> <span
                                class="fa arrow"></span>
                    </a>
                    <ul class="nav nav-second-level">
                        <li class="active"><a class="J_menuItem" href="/main">快捷入口</a></li>
                    </ul>
                </li>
                <#include "left.ftl" />
            </ul>
        </div>
    </nav>
    <!--左侧导航结束-->
    <!--右侧部分开始-->
    <div id="page-wrapper" class="gray-bg dashbard-1">
        <div class="row border-bottom">
            <nav class="navbar navbar-static-top" role="navigation" style="margin-bottom: 0">
                <div class="navbar-header minimalize-styl-2">
                    <a class="navbar-minimalize" style="color:#FFFFFF;line-height: 22px;" href="#"
                       title="收起菜单"><i class="fa fa-bars"></i> </a>
                    <span class="navbar-minimalize"
                          style=" margin:14px 5px 5px 0;padding:0 12px;color:#FFFFFF;line-height: 22px;font-size: 22px;">文&nbsp;档&nbsp;智&nbsp;能&nbsp;存&nbsp;储&nbsp;管&nbsp;理&nbsp;系&nbsp;统</span>
                </div>
                <ul class="nav navbar-top-links navbar-right">
                    <li class="dropdown">
                        <a class="right-sidebar-toggle" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="false">
                            <i class="fa">${user.name}</i>
                            <span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
                            <li><a href="#"><i class="fa"></i> 登录名：&nbsp;&nbsp; ${user.username}</a></li>
                            <li><a href="#"><i class="fa"></i> 姓名：&nbsp;&nbsp; &nbsp;&nbsp;${user.name}</a></li>
                            <li><a href="#"><i class="fa"></i> 所属部门：${user.deptName}</a></li>
                        </ul>
                    </li>
                    <li class="dropdown">
                        <a class="right-sidebar-toggle" id="dropdownMenu2" data-toggle="dropdown" aria-expanded="false">
                            <i class="fa fa-id-card">个人</i>
                            <span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu" aria-labelledby="dropdownMenu2">
                            <li><a onclick="openUser()" href="#"><i class="fa fa-id-card"></i> 个人中心</a></li>
                            <li><a href="${ctx}/logout"><i class="fa fa fa-sign-out"></i> 退出</a></li>
                        </ul>
                    </li>
                </ul>
            </nav>
        </div>
        <div class="row content-tabs">
            <button class="roll-nav roll-left J_tabLeft">
                <i class="fa fa-backward"></i>
            </button>
            <nav class="page-tabs J_menuTabs">
                <div class="page-tabs-content">
                    <a href="javascript:;" class="active J_menuTab" data-id="/main">首页</a>
                </div>
            </nav>
            <button class="roll-nav roll-right J_tabRight">
                <i class="fa fa-forward"></i>
            </button>
            <div class="btn-group roll-nav roll-right">
                <button class="dropdown J_tabClose" data-toggle="dropdown">
                    关闭操作
                </button>
                <ul role="menu" class="dropdown-menu dropdown-menu-right">
                    <li class="J_tabShowActive"><a>定位当前选项卡</a></li>
                    <li class="divider"></li>
                    <li class="J_tabCloseAll"><a>关闭全部选项卡</a></li>
                    <li class="J_tabCloseOther"><a>关闭其他选项卡</a></li>
                </ul>
            </div>
        </div>
        <div class="row J_mainContent" id="content-main">
            <iframe class="J_iframe" name="iframe0" width="100%" height="100%"
                    src="main" frameborder="0" data-id="/main" seamless></iframe>
        </div>
        <div class="footer">
            <div class="pull-right"><a href="http://www.hjjs.com/" target="_blank">河北汇金机电股份有限公司</a></div>
        </div>
    </div>
</div>
<!-- 全局js -->
<script src="${ctx}/static/jquery/jquery.min.js"></script>
<script src="${ctx}/static/bootstrap/js/bootstrap.min.js"></script>
<script src="${ctx}/static/jquery/jquery.slimscroll.min.js"></script>
<script type="text/javascript" src="${ctx}/js/index/app.js"></script>
<script type="text/javascript" src="${ctx}/js/index/contabs.js"></script>
<script src="${ctx}/static/jquery/jquery.metisMenu.js"></script>
<script src="${ctx}/static/layerui/layer.js"></script>
<script type="text/javascript">
    var branchName;
    var websocket = null;
    var websocket_connection = false;

    function connection() {
        // websocket = new WebSocket("ws://172.16.201.24:8181/add");
        websocket = new WebSocket("ws://127.0.0.1:8181/add");
        //连接发生错误的回调方法
        websocket.onerror = function () {
            websocket_connection = false;
            console.log("websocket连接错误！")
        };

        //连接成功建立的回调方法
        websocket.onopen = function (event) {
            websocket_connection = true;
            console.log("websocket连接成功！")
        };

        //接收到消息的回调方法
        // websocket.onmessage = function (event) {
        // };
        //连接关闭的回调方法
        websocket.onclose = function () {
            console.log("websocket连接关闭，重新连接！");
            websocket_connection = false;
            setTimeout(function () {
                connection();
            }, 1000);
        };
    }

    $(function () {
        branchName = "${user.deptName}";
        //判断当前浏览器是否支持WebSocket
        if ('WebSocket' in window) {
          //  connection();
        } else {
            alert('Not support websocket')
        }
    });
    //监听窗口关闭事件，当窗口关闭时，主动去关闭websocket连接，防止连接还没断开就关闭窗口，server端会抛异常。
    window.onbeforeunload = function () {
       // websocket.close();
    };

    //发送消息
    function send(message, callBack, param) {
        if (websocket_connection) {
            console.log("发送的消息为:", message);
            websocket.send(message);
            //连接关闭的回调方法
            websocket.onmessage = function (event) {
                // console.log("返回的消息:", event);
                callBack(event, param);
            }
        } else {
            layer.msg("连接socket失败，请刷新页面重连！");
        }
    }

    function openUser() {
        layer.open({
            type: 2,
            title: '个人设置',
            maxmin: true,
            shadeClose: false,
            area: ['800px', '600px'],
            content: 'sys/user/personal'
        });
    }

    function addCloseClick(param) {
        // $('.J_menuTabs').on('click', '.J_menuTab i', function (event) {
        //     console.log(param)
        //     $.each(param, function (index, light) {
        //         light.state = "1";
        //         top.send(JSON.stringify(light), function (event) {
        //             // console.log(event);
        //         });
        //     })
        // });
    }

</script>
</body>
</html>
